package cn.bopomo.dealer.base.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.bopomo.dealer.base.common.CommonConstant;
import cn.bopomo.dealer.base.common.ServiceConfig;
import cn.bopomo.dealer.base.service.IOperatorService;
import cn.bopomo.dealer.base.util.Page;
import cn.bopomo.dealer.base.vo.OperatorDetail;

public class ShowOperatorListAction extends BaseAction {

	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
//		if (!this.hasPermission(request)){
//			return this.findFailure(mapping);
//		}
		//获取当前操作员ID
		String userId = this.getUserId(request);
		if(userId == null){
			return this.findFailure(mapping);
		}
		//获取当前分页数
		String strPageSize = request.getParameter("pageSize");
		if (strPageSize == null || "".equals(strPageSize)){
			strPageSize = "1";
		}
		IOperatorService service = (IOperatorService)this.findService(ServiceConfig.OPERATOR_SERVICE);
		//获取当前操作员对象
		OperatorDetail operatorDetail = service.getOperatorDetail(userId);
		//获取查询列表
		Page resultPage = service.getOperatorListByParent(operatorDetail, Integer.parseInt(strPageSize),3);//CommonConstant.INT_ROWS_PER_PAGE);
		//设置分页查询的提交URL
		if (resultPage != null && resultPage.getList().size()>0){
			resultPage.setTarget(request.getRequestURI());
		}
		//设置对象并返回
		request.setAttribute(CommonConstant.KEY_OPERATOR_LIST_PAGE,resultPage);
		return this.findSuccess(mapping);
	}

}
